<?php include "../public/header.php"?>
<?php include "../public/header_public.php"?>
<body class="laytp-container">
<div style="height: 45px"></div>
<div id="opt_nav">
</div>
<div id="dialog">
    <div class="page-title" id="page-title">
        <div class="page-title-con">
            <span class="title">选择采购合同明细信息</span>
            <div class="move_title"></div>
            <div class="page-title-opt-list">
                <button class="layui-btn layui-btn-sm btn-dark marginr5" type="button" id="submit">确定</button>
                <span id="page-close" class="page-close" onclick="layer_close()">×</span>
            </div>
        </div>
    </div>
</div>

<div class="layui-card" id="search-form">
    <div class="layui-card-body">
        <form class="layui-form" id="TableSearchFormId" lay-filter="TableSearchForm" onkeydown="keyTableSearch('TableSearchForm', 'datalist')">
            <div class="layui-form-item">
                <div class="layui-row">
                    <div class="layui-col-md3">
                        <label class="layui-form-label">名称及规格</label>
                        <div class="layui-input-block">
                            <input type="text" name="name" placeholder="请输入" class="layui-input" autocomplete="off">
                        </div>
                    </div>
                    <div class="layui-col-md3">
                        <div class="layui-form-item search-div">
                            <div class="layui-form-item layui-inline">
                                <button class="laytp-btn laytp-btn-md laytp-btn-primary" id="TableSearchButton" type="button"><i class="layui-icon layui-icon-search"></i>查询</button>
                                <button class="layui-btn layui-btn-primary" onclick="listTableReset()" id="TableSearchReset" type="reset" ><i class="layui-icon layui-icon-refresh"></i>重置</button>
                            </div>
                        </div>
                    </div>
                </div>
            </div>
        </form>
    </div>
</div>

<div class="layui-card" id="table-card">
    <div class="layui-card-body">
        <div class="layui-row">
            <div class="layui-col-md12" id="table_list">
                <div class="layui-card-body">
                    <table id="datalist" lay-filter="datalist"></table>
                </div>
            </div>
        </div>
    </div>
</div>

<script type="text/javascript">
    // 单选多选分类 默认单选 choose_type传值为多选
    var choose_type = getQueryVariable('choose_type');
    if(choose_type === undefined || choose_type === false){
        choose_type = 'checkbox';
    }else{
        choose_type = 'radio';
    }

    var parent_dom = getQueryVariable('dom');
    var parent_domkey = getQueryVariable('domkey');
    var parent_page = getQueryVariable('page');
    var parent_caiid = getQueryVariable('caiid') || 0;


    var labour_shennum_hide=false,labour_henum_hide=false,jinnum_hide=false,explain_hide=false,runum_hide=false,sheng_runum_hide=false,rumoney_hide=false
    subbao_shennum_hide=false,subbao_henum_hide=false;
    if(parent_page == 'stuff_ru' || parent_page == 'stuff_ru_edit' || parent_page == 'stuff_ru_one'){
        labour_shennum_hide = true;
        labour_henum_hide = true;
        jinnum_hide = true;
        explain_hide = true;
        subbao_shennum_hide = true;
        subbao_henum_hide = true;
    }
    if(parent_page == 'stuff_cai' || parent_page == 'stuff_cai_edit' || parent_page == 'stuff_cai_one'){
        labour_shennum_hide = true;
        labour_henum_hide = true;
        jinnum_hide = true;
        explain_hide = true;
        subbao_shennum_hide = true;
        subbao_henum_hide = true;
    }
    if(parent_page == 'labour_shen' || parent_page == 'labour_shen_one' || parent_page == 'labour_jie' || parent_page == 'labour_jie_one'){
        runum_hide = true;
        sheng_runum_hide = true;
        rumoney_hide = true;
        jinnum_hide = true;
        subbao_shennum_hide = true;
        subbao_henum_hide = true;
    }
    if(parent_page == 'subbao_shen' || parent_page == 'subbao_shen_one' || parent_page == 'subbao_jie' || parent_page == 'subbao_jie_one' ||
        parent_page == 'subbao_shen_one'){
        runum_hide = true;
        sheng_runum_hide = true;
        rumoney_hide = true;
        labour_shennum_hide = true;
        labour_henum_hide = true;
        jinnum_hide = true;
    }
    if(parent_page == 'device_jin_one'){
        runum_hide = true;
        sheng_runum_hide = true;
        rumoney_hide = true;
        labour_shennum_hide = true;
        labour_henum_hide = true;
        subbao_shennum_hide = true;
        subbao_henum_hide = true;
    }

    layui.use(["laytp",'laypage','table','dropdown','form','soulTable'], function () {
        var laypage = layui.laypage, table = layui.table, dropdown = layui.dropdown, form = layui.form, soulTable = layui.soulTable;

        $('#TableSearchReset').click(function () {
            $('.xmselect_div>xm-select').find('.xm-label-block').css('display','none');
            $('.xmselect_div').append('<div class="xmselect_title">请选择</div>');
            searchTableFunc(form, table)
        });

        $("#cols_table").hide();
        $("#export_table").hide();
        table.render({
            elem: "#datalist",id: "datalist"
            ,url: facade.url(ask_opt_get_contract_cai_list),where: {caiid:parent_caiid}, page: true, height: 'full-140'
            ,soulSort: TabInit.soulSort,method: TabInit.method, toolbar: TabInit.toolbar, overflow: TabInit.overflow
            ,defaultToolbar: ['', '', ''],filter: TabInit.filter
            ,request: TabInit.request,response: TabInit.response,contextmenu:get_table_contextmenu(soulTable)
            ,parseData: function(res){
                render_from();
                return {
                    "code": res.code,
                    "msg": res.message,
                    "count": res.data.data.total,
                    "data": res.data.data.data
                };
            }
            ,cols: [[
                {type:choose_type}
                ,{field: 'name', title: '名称及规格'}
                ,{field: 'unit', title: '单位'}
                ,{field: 'num', title: '采购数量'}
                ,{field: 'price', title: '采购单价(元)'}
                ,{field: 'money', title: '采购金额(元)'}
                ,{field: 'runum', title: '累计入库数量',hide:runum_hide}
                ,{field: 'sheng_runum', title: '剩余可入库数量',hide:sheng_runum_hide}
                ,{field: 'rumoney', title: '累计入库金额(元)',hide:rumoney_hide}
                ,{field: 'labour_shennum', title: '累计申报数量',hide:labour_shennum_hide}
                ,{field: 'labour_henum', title: '累计核定数量',hide:labour_henum_hide}
                ,{field: 'subbao_shennum', title: '累计申报数量',hide:subbao_shennum_hide}
                ,{field: 'subbao_henum', title: '累计核定数量',hide:subbao_henum_hide}
                ,{field: 'jinnum', title: '已进场数量',hide:jinnum_hide}
                ,{field: 'explain', title: '备注',hide:explain_hide}
            ]]
            ,done : function(res, curr, count){
                $(".layui-table-tool").remove()
                soulTable.render(this);
            }
        });
        listTableSearch(form, table);


        $('#submit').on('click', function () {
            var checkStatus = layui.table.checkStatus('datalist');
            var data = checkStatus.data;
            if(data.length < 1){
                facade.error("请选择数据");return false;
            }

            if(parent_page == 'stuff_ru'){
                var str = '';
                var nums = $("#ru_list tr", parent.document).length;
                for (var key in data){
                    nums++;
                    str += '<tr>';
                    str += '<td style="width: 45px">'+nums+'</td>';
                    str += '<td>';

                    if(parseFloat(data[key].sheng_runum) <= 0){
                        facade.error('第'+data[key].hanghao+'行数据，无剩余可入库数量，请重新选择');
                        return false;
                    }

                    str += '<input type="text" listid="'+data[key].id+'" disabled value="'+data[key].name+'" class="layui-input disabled name">';
                    str += '</td>';
                    str += '<td><input type="text" disabled class="layui-input disabled unit" value="'+data[key].unit+'"></td>';
                    str += '<td><input type="text" class="layui-input price" value="'+data[key].price+'"></td>';
                    str += '<td><input type="text" class="layui-input num"></td>';
                    str += '<td><input type="text" disabled class="layui-input money disabled"></td>';
                    str += '<td><input type="text" class="layui-input explain"></td>';
                    str += '</tr>';
                }
                $("#ru_list", parent.document).append(str);
                if (typeof(window.parent.update_refresh_row_func)!="undefined"){
                    window.parent.update_refresh_row_func();
                }
            }else if(parent_page == 'stuff_ru_edit'){
                var str = '';
                var nums = $("#ru_list tr", parent.document).length;
                for (var key in data){
                    nums++;
                    str += '<tr>';
                    str += '<td style="width: 45px">'+nums+'</td>';
                    str += '<td>';
                    str += '<input type="text" listid="'+data[key].id+'" disabled value="'+data[key].name+'" class="layui-input disabled name">';
                    str += '</td>';
                    str += '<td><input type="text" class="layui-input disabled unit" value="'+data[key].unit+'"></td>';
                    str += '<td><input type="text" class="layui-input price" value="'+data[key].price+'"></td>';
                    str += '<td><input type="text" class="layui-input num"></td>';
                    str += '<td><input type="text" disabled class="layui-input money disabled"></td>';
                    str += '<td><input type="text" class="layui-input explain"></td>';
                    str += '</tr>';
                }
                $("#ru_list", parent.document).append(str);
                if (typeof(window.parent.update_refresh_row_func)!="undefined"){
                    window.parent.update_refresh_row_func();
                }
            }else if(parent_page == 'stuff_ru_one'){
                $("#ru_list tr", parent.document).eq(parent_domkey).find('.name').val(data[0].name).attr('listid',data[0].id);
                $("#ru_list tr", parent.document).eq(parent_domkey).find('.unit').val(data[0].unit);
                $("#ru_list tr", parent.document).eq(parent_domkey).find('.price').val(data[0].price);
                if (typeof(window.parent.update_refresh_row_func)!="undefined"){
                    window.parent.update_refresh_row_func();
                }
            }else if(parent_page == 'stuff_cai'){
                var str = '';
                var nums = $("#cai_list tr", parent.document).length;
                for (var key in data){
                    nums++;
                    str += '<tr>';
                    str += '<td style="width: 45px">'+nums+'</td>';
                    str += '<td>';
                    str += '<input type="text" listid="'+data[key].id+'" disabled value="'+data[key].name+'" class="layui-input disabled name">';
                    str += '</td>';
                    str += '<td><input type="text" disabled class="layui-input disabled unit" value="'+data[key].unit+'"></td>';
                    str += '<td><input type="text" class="layui-input price" value="'+data[key].price+'"></td>';
                    str += '<td><input type="text" class="layui-input num"></td>';
                    str += '<td><input type="text" disabled class="layui-input money disabled"></td>';
                    str += '<td><input type="text" class="layui-input explain"></td>';
                    str += '</tr>';
                }
                $("#cai_list", parent.document).append(str);
                if (typeof(window.parent.update_refresh_row_func)!="undefined"){
                    window.parent.update_refresh_row_func();
                }
            }else if(parent_page == 'stuff_cai_edit'){
                var str = '';
                var nums = $("#cai_list tr", parent.document).length;
                for (var key in data){
                    nums++;
                    str += '<tr>';
                    str += '<td style="width: 45px">'+nums+'</td>';
                    str += '<td>';
                    str += '<input type="text" listid="'+data[key].id+'" disabled value="'+data[key].name+'" class="layui-input disabled name">';
                    str += '</td>';
                    str += '<td><input type="text" class="layui-input disabled unit" value="'+data[key].unit+'"></td>';
                    str += '<td><input type="text" class="layui-input price" value="'+data[key].price+'"></td>';
                    str += '<td><input type="text" class="layui-input num"></td>';
                    str += '<td><input type="text" disabled class="layui-input money disabled"></td>';
                    str += '<td><input type="text" class="layui-input explain"></td>';
                    str += '</tr>';
                }
                $("#cai_list", parent.document).append(str);
                if (typeof(window.parent.update_refresh_row_func)!="undefined"){
                    window.parent.update_refresh_row_func();
                }
            }else if(parent_page == 'stuff_cai_one'){
                $("#cai_list tr", parent.document).eq(parent_domkey).find('.name').val(data[0].name).attr('listid',data[0].id);
                $("#cai_list tr", parent.document).eq(parent_domkey).find('.unit').val(data[0].unit);
                $("#cai_list tr", parent.document).eq(parent_domkey).find('.price').val(data[0].price);
                if (typeof(window.parent.update_refresh_row_func)!="undefined"){
                    window.parent.update_refresh_row_func();
                }
            }else if(parent_page == 'subbao_shen'){
                var str = '';
                var nums = $("#list_list tr", parent.document).length;
                for (var key in data){
                    nums++;
                    str += '<tr>';
                    str += '<td style="width: 45px">'+nums+'</td>';
                    str += '<td>';
                    str += '<input type="text" onclick="choose_contract_cai_list_one(this)" listid="'+data[key].id+'" readonly value="'+data[key].name+'" class="layui-input name disabled">';
                    str += '</td>';
                    str += '<td><input type="text" readonly class="layui-input unit disabled" value="'+data[key].unit+'"></td>';
                    str += '<td><input type="text" readonly class="layui-input price disabled" value="'+data[key].price+'"></td>';
                    str += '<td><input type="text" readonly class="layui-input num disabled" value="'+data[key].num+'"></td>';
                    str += '<td><input type="number" class="layui-input shennum"></td>';
                    str += '<td><input type="number" disabled class="layui-input shenmoney disabled"></td>';
                    str += '<td><input type="number" class="layui-input henum"></td>';
                    str += '<td><input type="number" class="layui-input money"></td>';
                    str += '<td><input type="text" class="layui-input explain"></td>';
                    str += '</tr>';
                }
                $("#list_list", parent.document).append(str);
                if (typeof(window.parent.update_refresh_row_func)!="undefined"){
                    window.parent.update_refresh_row_func();
                }
            }else if(parent_page == 'subbao_shen_one'){
                $("#list_list tr", parent.document).eq(parent_domkey).find('.name').val(data[0].name).attr('listid',data[0].id);
                $("#list_list tr", parent.document).eq(parent_domkey).find('.unit').val(data[0].unit);
                $("#list_list tr", parent.document).eq(parent_domkey).find('.price').val(data[0].price);
                $("#list_list tr", parent.document).eq(parent_domkey).find('.num').val(data[0].num);
                if (typeof(window.parent.update_refresh_row_func)!="undefined"){
                    window.parent.update_refresh_row_func();
                }
            }else if(parent_page == 'subbao_jie'){
                var str = '';
                var nums = $("#list_list tr", parent.document).length;
                for (var key in data){
                    nums++;
                    str += '<tr>';
                    str += '<td style="width: 45px">'+nums+'</td>';
                    str += '<td>';
                    str += '<input type="text" onclick="choose_contract_cai_list_one(this)" listid="'+data[key].id+'" readonly value="'+data[key].name+'" class="layui-input name disabled">';
                    str += '</td>';
                    str += '<td><input type="text" readonly class="layui-input unit disabled" value="'+data[key].unit+'"></td>';
                    str += '<td><input type="text" readonly class="layui-input price disabled" value="'+data[key].price+'"></td>';
                    str += '<td><input type="text" readonly class="layui-input connum disabled" value="'+data[key].num+'"></td>';
                    str += '<td><input type="text" readonly class="layui-input conmoney disabled" value="'+data[key].money+'"></td>';
                    str += '<td><input type="text" readonly class="layui-input henum disabled" value="'+data[key].subbao_henum+'"></td>';
                    str += '<td><input type="number" class="layui-input shinum"></td>';
                    str += '<td><input type="number" class="layui-input shiprice"></td>';
                    str += '<td><input type="number" class="layui-input money"></td>';
                    str += '<td><input type="text" class="layui-input explain"></td>';
                    str += '</tr>';
                }
                $("#list_list", parent.document).append(str);
                if (typeof(window.parent.update_refresh_row_func)!="undefined"){
                    window.parent.update_refresh_row_func();
                }
            }else if(parent_page == 'subbao_jie_one'){
                $("#list_list tr", parent.document).eq(parent_domkey).find('.name').val(data[0].name).attr('listid',data[0].id);
                $("#list_list tr", parent.document).eq(parent_domkey).find('.unit').val(data[0].unit);
                $("#list_list tr", parent.document).eq(parent_domkey).find('.price').val(data[0].price);
                $("#list_list tr", parent.document).eq(parent_domkey).find('.connum').val(data[0].num);
                $("#list_list tr", parent.document).eq(parent_domkey).find('.conmoney').val(data[0].money);
                $("#list_list tr", parent.document).eq(parent_domkey).find('.henum').val(data[0].subbao_henum);
                if (typeof(window.parent.update_refresh_row_func)!="undefined"){
                    window.parent.update_refresh_row_func();
                }
            }else if(parent_page == 'labour_shen'){
                var str = '';
                var nums = $("#list_list tr", parent.document).length;
                for (var key in data){
                    nums++;
                    str += '<tr>';
                    str += '<td style="width: 45px">'+nums+'</td>';
                    str += '<td>';
                    str += '<input type="text" onclick="choose_contract_cai_list_one(this)" listid="'+data[key].id+'" readonly value="'+data[key].name+'" class="layui-input name disabled">';
                    str += '</td>';
                    str += '<td><input type="text" readonly class="layui-input unit disabled" value="'+data[key].unit+'"></td>';
                    str += '<td><input type="text" readonly class="layui-input price disabled" value="'+data[key].price+'"></td>';
                    str += '<td><input type="text" readonly class="layui-input num disabled" value="'+data[key].num+'"></td>';
                    str += '<td><input type="number" class="layui-input shennum"></td>';
                    str += '<td><input type="number" disabled class="layui-input shenmoney disabled"></td>';
                    str += '<td><input type="number" class="layui-input henum"></td>';
                    str += '<td><input type="number" class="layui-input money"></td>';
                    str += '<td><input type="text" class="layui-input explain"></td>';
                    str += '</tr>';
                }
                $("#list_list", parent.document).append(str);
                if (typeof(window.parent.update_refresh_row_func)!="undefined"){
                    window.parent.update_refresh_row_func();
                }
            }else if(parent_page == 'labour_shen_one'){
                $("#list_list tr", parent.document).eq(parent_domkey).find('.name').val(data[0].name).attr('listid',data[0].id);
                $("#list_list tr", parent.document).eq(parent_domkey).find('.unit').val(data[0].unit);
                $("#list_list tr", parent.document).eq(parent_domkey).find('.price').val(data[0].price);
                $("#list_list tr", parent.document).eq(parent_domkey).find('.num').val(data[0].num);
                if (typeof(window.parent.update_refresh_row_func)!="undefined"){
                    window.parent.update_refresh_row_func();
                }
            }else if(parent_page == 'labour_jie'){
                var str = '';
                var nums = $("#list_list tr", parent.document).length;
                for (var key in data){
                    nums++;
                    str += '<tr>';
                    str += '<td style="width: 45px">'+nums+'</td>';
                    str += '<td>';
                    str += '<input type="text" onclick="choose_contract_cai_list_page_subbaojie_one(this)" listid="'+data[key].id+'" readonly value="'+data[key].name+'" class="layui-input name disabled">';
                    str += '</td>';
                    str += '<td><input type="text" readonly class="layui-input unit disabled" value="'+data[key].unit+'"></td>';
                    str += '<td><input type="text" readonly class="layui-input price disabled" value="'+data[key].price+'"></td>';
                    str += '<td><input type="text" readonly class="layui-input connum disabled" value="'+data[key].num+'"></td>';
                    str += '<td><input type="text" readonly class="layui-input conmoney disabled" value="'+data[key].money+'"></td>';
                    str += '<td><input type="text" readonly class="layui-input henum disabled" value="'+data[key].labour_henum+'"></td>';
                    str += '<td><input type="number" class="layui-input shinum"></td>';
                    str += '<td><input type="number" class="layui-input shiprice"></td>';
                    str += '<td><input type="number" class="layui-input money"></td>';
                    str += '<td><input type="text" class="layui-input explain"></td>';
                    str += '</tr>';
                }
                $("#list_list", parent.document).append(str);
                if (typeof(window.parent.update_refresh_row_func)!="undefined"){
                    window.parent.update_refresh_row_func();
                }
            }else if(parent_page == 'labour_jie_one'){
                $("#list_list tr", parent.document).eq(parent_domkey).find('.name').val(data[0].name).attr('listid',data[0].id);
                $("#list_list tr", parent.document).eq(parent_domkey).find('.unit').val(data[0].unit);
                $("#list_list tr", parent.document).eq(parent_domkey).find('.price').val(data[0].price);
                $("#list_list tr", parent.document).eq(parent_domkey).find('.connum').val(data[0].num);
                $("#list_list tr", parent.document).eq(parent_domkey).find('.conmoney').val(data[0].money);
                $("#list_list tr", parent.document).eq(parent_domkey).find('.henum').val(data[0].labour_henum);
                if (typeof(window.parent.update_refresh_row_func)!="undefined"){
                    window.parent.update_refresh_row_func();
                }
            }else if(parent_page == 'device_jin_one'){
                openPage('choose_contract_cai_page_devicejin_guide.php?id='+data[0].id+'&name='+decodeURI(data[0].name)+'&unit='+decodeURI(data[0].unit)+'&price='+data[0].price, '770px', '490px')


                return false;
            }else if(parent_page == 'contract_bian'){
                var str = '';
                var nums = $("#list_list tr", parent.document).length;
                for (var key in data){
                    nums++;
                    str += '<tr>';
                    str += '<td style="width: 45px">'+nums+'</td>';
                    str += '<td class="layui-hide"><input type="text" onclick="choose_engin_budget_list_one(this)" subid="'+data[key].subid+'" value="'+data[key].subname+'" class="layui-input subname disabled"></td>';
                    str += '<td class="layui-hide"><input type="text" disabled value="'+data[key].guiname+'" class="layui-input guiname disabled"></td>';
                    str += '<td>';
                    str += '<input type="text" onclick="choose_contract_cai_list_one(this)" listid="'+data[key].id+'" readonly value="'+data[key].name+'" class="layui-input name disabled">';
                    str += '</td>';
                    str += '<td><input type="text" readonly class="layui-input unit disabled" value="'+data[key].unit+'"></td>';
                    str += '<td><input type="text" readonly class="layui-input num_yuan disabled" value="'+data[key].num+'"></td>';
                    str += '<td><input type="text" readonly class="layui-input price_yuan disabled" value="'+data[key].price+'"></td>';
                    str += '<td><input type="text" readonly class="layui-input money_yuan disabled" value="'+data[key].money+'"></td>';
                    str += '<td><input type="number" class="layui-input num_tiao"></td>';
                    str += '<td><input type="number" class="layui-input price_tiao"></td>';
                    str += '<td><input type="number" readonly class="layui-input num disabled"></td>';
                    str += '<td><input type="number" readonly class="layui-input price disabled"></td>';
                    str += '<td><input type="number" readonly class="layui-input money disabled"></td>';
                    str += '<td><input type="text" class="layui-input explain"></td>';
                    str += '<td><input type="text" readonly class="layui-input lai disabled" value="合同"></td>';
                    str += '</tr>';
                }
                $("#list_list", parent.document).append(str);
                if (typeof(window.parent.update_refresh_row_func)!="undefined"){
                    window.parent.update_refresh_row_func();
                }
            }else if(parent_page == 'contract_bian_one'){
                $("#list_list tr", parent.document).eq(parent_domkey).find('.name').val(data[0].name).attr('listid',data[0].id);
                $("#list_list tr", parent.document).eq(parent_domkey).find('.guige').val(data[0].guige);
                $("#list_list tr", parent.document).eq(parent_domkey).find('.unit').val(data[0].unit);
                $("#list_list tr", parent.document).eq(parent_domkey).find('.num_yuan').val(data[0].num);
                $("#list_list tr", parent.document).eq(parent_domkey).find('.price_yuan').val(data[0].price);
                $("#list_list tr", parent.document).eq(parent_domkey).find('.money_yuan').val(data[0].money);
                if (typeof(window.parent.update_refresh_row_func)!="undefined"){
                    window.parent.update_refresh_row_func();
                }
            }else{

            }


            layer_close();
        });

    });
</script>
</body>
</html>
